package com.ruoyi.am.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.am.domain.AmRosterLog;
import com.ruoyi.am.service.IAmRosterLogService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 调班记录Controller
 * 
 * @author hkkk
 * @date 2020-12-09
 */
@Controller
@RequestMapping("/am/log")
public class AmRosterLogController extends BaseController
{
    private String prefix = "am/log";

    @Autowired
    private IAmRosterLogService amRosterLogService;

    @RequiresPermissions("am:log:view")
    @GetMapping()
    public String log()
    {
        return prefix + "/log";
    }

    /**
     * 查询调班记录列表
     */
    @RequiresPermissions("am:log:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AmRosterLog amRosterLog)
    {
        startPage();
        List<AmRosterLog> list = amRosterLogService.selectAmRosterLogList(amRosterLog);
        return getDataTable(list);
    }

    /**
     * 导出调班记录列表
     */
    @RequiresPermissions("am:log:export")
    @Log(title = "调班记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AmRosterLog amRosterLog)
    {
        List<AmRosterLog> list = amRosterLogService.selectAmRosterLogList(amRosterLog);
        ExcelUtil<AmRosterLog> util = new ExcelUtil<AmRosterLog>(AmRosterLog.class);
        return util.exportExcel(list, "log");
    }

    /**
     * 新增调班记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存调班记录
     */
    @RequiresPermissions("am:log:add")
    @Log(title = "调班记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AmRosterLog amRosterLog)
    {
        return toAjax(amRosterLogService.insertAmRosterLog(amRosterLog));
    }

    /**
     * 修改调班记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        AmRosterLog amRosterLog = amRosterLogService.selectAmRosterLogById(id);
        mmap.put("amRosterLog", amRosterLog);
        return prefix + "/edit";
    }

    /**
     * 修改保存调班记录
     */
    @RequiresPermissions("am:log:edit")
    @Log(title = "调班记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AmRosterLog amRosterLog)
    {
        return toAjax(amRosterLogService.updateAmRosterLog(amRosterLog));
    }

    /**
     * 删除调班记录
     */
    @RequiresPermissions("am:log:remove")
    @Log(title = "调班记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(amRosterLogService.deleteAmRosterLogByIds(ids));
    }
}
